<?php
	class Model_link extends CI_Model{
		protected $_table = "tbl_content";
		protected $_subcont = "tbl_content_detail";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function listall($off,$start){
			$this->db->limit($off,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function listcate(){
			return $this->db->get($this->_table)->result_array();
		}
		public function count_all(){
			return $this->db->count_all($this->_table);
		}
		public function listall_sub($off,$start){
			$this->db->join("tbl_content","tbl_content.content_id = tbl_content_detail.content_id");
			$this->db->limit($off,$start);
			return $this->db->get($this->_subcont)->result_array();
		}
		public function count_all_sub(){
			$this->db->join("tbl_content","tbl_content.content_id = tbl_content_detail.content_id");
			return $this->db->count_all_results($this->_subcont);
		}
		public function add($value){
			$this->db->insert($this->_table,$value);
		}
		public function addsub($value){
			$this->db->insert($this->_subcont,$value);
		}
		public function getdata($id){
			$this->db->where("content_id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function getdatasub($id){
			$this->db->where("cont_id",$id);
			return $this->db->get($this->_subcont)->row_array();
		}
		public function update($data,$id){
			$this->db->where("content_id",$id);
			$this->db->update($this->_table,$data);
		}
		public function updatesub($data,$id){
			$this->db->where("cont_id",$id);
			$this->db->update($this->_subcont,$data);
		}
		public function del($id){
			$this->db->where("content_id",$id);
			$this->db->delete($this->_table);
		}
		public function delsub($id){
			$this->db->where("cont_id",$id);
			$this->db->delete($this->_subcont);
		}
	}